import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('GPS定位'),
        ),
        body: LocWidget(),
      ),
    );
  }
}

class LocWidget extends StatefulWidget {
  @override
  _LocWidgetState createState() => _LocWidgetState();
}

class _LocWidgetState extends State<LocWidget> {
  String locInfo = "";

  getLoc() async {
    setState(() {
      locInfo = "正在定位\n";
    });
    Position position = await getCurrentPosition(
        forceAndroidLocationManager: true,
        desiredAccuracy: LocationAccuracy.high);
    setState(() {
      locInfo += "当前位置:${position.latitude}+${position.longitude}";
    });
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text(locInfo),
        RaisedButton(
          onPressed: getLoc,
          child: Text('获取位置'),
        )
      ],
    );
  }
}

getCurrentPosition({bool forceAndroidLocationManager, LocationAccuracy desiredAccuracy}) {
}
